package com.yugao.fintech.antelope.infra.weixin.mp.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yugao.fintech.antelope.infra.weixin.mp.mapper.MpUserMapper;
import com.yugao.fintech.antelope.infra.weixin.mp.model.entity.MpUser;
import com.yugao.fintech.framework.assistant.utils.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 公众号粉丝 仓储层
 *
 
 */
@Slf4j
@Repository
public class MpUserManager extends ServiceImpl<MpUserMapper, MpUser>
    implements IService<MpUser> {

    public MpUser getUser(String appId, String openId) {
        LambdaQueryWrapper<MpUser> lqw = MpUser.lqw()
                .eq(MpUser::getMpAppId, appId).eq(MpUser::getOpenId, openId);
        return this.getOne(lqw);
    }

    public List<MpUser> listByAppIdAndOpenIds(String mpAppId, List<String> openIds) {
        LambdaQueryWrapper<MpUser> lqw = MpUser.lqw()
                .eq(MpUser::getMpAppId, mpAppId).in(CollectionUtils.isNotEmpty(openIds), MpUser::getOpenId, openIds);
        return this.list(lqw);
    }
}
